package com.yoomiito.app.act;

import com.yoomiito.app.base.AppConfig;
import com.yoomiito.app.base.BaseActPresenter;
import com.yoomiito.app.model.home.FreeActList;
import com.yoomiito.app.net.YmApi;

import cn.droidlover.xdroidmvp.net.ApiException;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.BaseModel;
import cn.droidlover.xdroidmvp.net.XApi;

public class FreeBuyPresenter extends BaseActPresenter<FreeBuyActivity> {

    public FreeBuyPresenter(AppConfig appConfig) {
        super(appConfig);
    }

    public void getFreeGoodsList(String id){
        YmApi.getYmService()
                .getFreeGoodsList(id)
                .compose(getV().bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(new ApiSubscriber<FreeActList>(handleException()) {
                    @Override
                    public void onSuccess(FreeActList freeActList) {
                        getV().setFreeGoods(freeActList);
                    }

                    @Override
                    public void onFail(ApiException error) {
                        getV().finishAct();
                    }
                });
    }
}
